using Castle.Core.Interceptor;
using Castle.DynamicProxy;

namespace FluentSilverlight.MVVM
{
    public class AutoNotifyPropertyChangedProxyCreator
    {
        public TModel Create<TModel>(params object[] constructorArgs) where TModel : IAutoNotifyPropertyChanged
        {
            var interceptor = new AutoNotifyPropertyChangedInterceptor<TModel>();
            var interceptors = new IInterceptor[] { interceptor };

            var proxyGenerator = new ProxyGenerator(new PersistentProxyBuilder());

            return (TModel)proxyGenerator.CreateClassProxy(typeof(TModel), interceptors, constructorArgs);            
        }
    }
}